package com.cjg.netCode;

import java.net.DatagramPacket;
import java.net.DatagramSocket;


public class charServiceUdp {
    public static void main(String[] args) throws Exception {
        //创建接收端口
        DatagramSocket socket = new DatagramSocket(7777);

        while (true){
            //接收数据
            byte[] bytes = new byte[1024];
            DatagramPacket Packet = new DatagramPacket(bytes,0,bytes.length);
            socket.receive(Packet); //阻塞式 接受包

            byte[] data = Packet.getData();
            String s = new String(data, 0, data.length);
            System.out.println(s);

            if (s.equals("bye")){

                break;
            }
        }
        socket.close();



    }
}
